const q = require('./q')
function formatTime(date, num = 1) {
  date = new Date(date);
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()

  if (num == 1) {
    return [year, month, day].map(formatNumber).join('-')
  } else if (num == 2) {
    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute].map(formatNumber).join(':')
  } else if (num == 3) {
    return [hour, minute].map(formatNumber).join(':')
  }
  // return [year, month, day].map(formatNumber).join('.') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}


function randomLetter() {
  let letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
  let randomnum = parseInt(Math.random() * 26);
  return letters[randomnum];
}

// function pay(app, credential, id, bool = true, question) {
//   return q.Promise((resolve, reject) => {
//     let self = this;
//     let wx_lite = credential.wx_lite;
//     wx.requestPayment({
//       timeStamp: wx_lite.timeStamp,
//       nonceStr: wx_lite.nonceStr,
//       package: wx_lite.package,
//       signType: wx_lite.signType,
//       paySign: wx_lite.paySign,
//       success: function () {
//         resolve(true);
//         if (bool) {
//           setTimeout(() => {
//             wx.navigateTo({ url: '/pages/success/success?type=1&back=1&idx=1&id=' + id + '&q=' + question });
//           }, 100);
//         }
//       },
//       fail: function (err) {
//         reject(false);
//         app.showModel({ msg: err });
//       },
//       complete: function (complete) {
//       }
//     });
//   });
// }


module.exports = {
  formatTime: formatTime,
}
